package reign.network.host;

import java.util.HashMap;
import java.util.UUID;
import java.util.logging.Logger;
import reign.network.user.User;

public class Session {

	private HashMap<String,User> users;
	private String name;
	private UUID id;
	private Logger logger;
	private boolean locked;
	
	public Session(UUID ID,String Name)
	{
		users = new HashMap<String,User>();
		//logger = Logger.getLogger("Session:Name:" + name.replace(' ','_') + "ID:" + id);
		setName(Name);
		locked = false;
		id = ID;
	}
	
	public Session(UUID ID,String Name,User [] addUs)
	{
		users = new HashMap<String,User>();
		//logger = Logger.getLogger("Session:Name:" + name.replace(' ','_') + "ID:" + id);
		setName(Name);
		locked = false;
		id = ID;
		for(int i = 0; i < addUs.length;i++)
		{
			addUser(addUs[i]);
		}
	}
	
	public void lock()
	{
		locked = true;
	}
	
	public boolean isLocked()
	{
		return locked;
	}
	
	public boolean addUser(User addMe)
	{
		if(!locked && users.get(addMe.getUsername()) != null)
		{
			users.put(addMe.getUsername(),addMe);
			return true;
		}
		else
		{
			//logger.warning("User " + addMe.getUsername() + "Couldn't is already Added");
			return false;
		}
	}
	
	public void end()
	{
		locked = false;
	}
	
	public User[] getUsers()
	{
		User[] returnUs = users.values().toArray(new User[0]);
		return returnUs;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
	
}
